package com.adulcimer.controllers;


import cn.dev33.satoken.annotation.SaIgnore;
import com.adulcimer.core.tools.R;
import com.adulcimer.models.dto.user.UserLoginDto;
import com.adulcimer.models.dto.user.UserSignDto;
import com.adulcimer.models.vo.InfoVo;
import com.adulcimer.models.vo.UserVo;
import com.adulcimer.services.AccountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Simon
 * @create 2025/7/18
 * @Description
 **/

@RestController
@RequestMapping("/api/account")
@Tag(name = "用户接口", description = "用户接口")
public class AccountController extends BaseController{

    @Resource
    private AccountService accountService;

    @PostMapping("/login")
    @Operation(summary = "登录")
    @SaIgnore
//    @CrossOrigin(origins = "http://172.16.0.152", allowCredentials = "true")
    public R<String> login(@RequestBody @Validated UserLoginDto userLoginDto){
        String token =accountService.login(userLoginDto);
        return R.ok(token);
    }

    @PostMapping("/logout")
    @Operation(summary = "注销")
    public R<String> logout(){
        accountService.logout(getToken(),getUserId());
        return R.ok();
    }


    @PostMapping("/sign")
    @Operation(summary = "注册")
    @SaIgnore
    public R<String> sign(@RequestBody @Validated UserSignDto userSignDto){
        accountService.sign(userSignDto);
        return R.ok();
    }



    @Operation(summary = "获取用户信息")
    @GetMapping("/getUserInfo")
    public R<InfoVo> getUserInfo(){
        String userId = getUserId();
        String token = getToken();
        String userAgent = getUserAgent();
        return R.ok(new InfoVo(userId,token,userAgent));
    }

    //当前用户的信息
    @Operation(summary = "获取当前用户信息")
    @GetMapping("/getCurrentUserInfo")
    public R<UserVo> getCurrentUserInfo(){
        UserVo byUserId = accountService.getByUserId();
        return R.ok(byUserId);
    }

    //TODO: 修改密码接口


    //TODO: 删除用户

    //TODO: 添加/修改用户

    //TODO: 赋予管理员权限


}

